/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * 知启蒙Servlet兼容库（zhiqim_servlet）在LGPL3.0协议下开源：https://www.zhiqim.com/gitcan/zhiqim/zhiqim_servlet.htm
 *
 * This file is part of [zhiqim_servlet].
 * 
 * [zhiqim_servlet] is free software: you can redistribute
 * it and/or modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * [zhiqim_servlet] is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with [zhiqim_servlet].
 * If not, see <http://www.gnu.org/licenses/>.
 */
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.server.session.HashSessionManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.webapp.WebAppContext;
import org.zhiqim.kernel.util.Ints;

/**
 * 定义Jetty启动类，用于开发时调试
 *
 * @version v1.0.0 @author zhichenggang 2017-1-7 新建与整理
 */
public class Jetty
{
    public static void main(String[] args) throws Exception
    {
        int port = 80;String resourceBase = "WebRoot";
        if (args != null && args.length > 0)
        {
            port = Ints.toInt(args[0], 80);
            if (args.length > 1)
                resourceBase = args[1];
        }
        
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(port);
        
        WebAppContext context = new WebAppContext();
        context.setContextPath("/");
        context.setResourceBase(resourceBase);
        context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        context.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
        context.setSessionHandler(new SessionHandler(new HashSessionManager()));
        context.setThrowUnavailableOnStartupException(true);
        
        Server server = new Server();
        server.addConnector(connector);
        server.setHandler(context);
        
        server.start();
    }
}
